Rhapsody Developer Release Copyright (C)1997 by Apple Computer, Inc. All Rights Reserved.
This file contains release notes for the Developer Release of the Terminal application. For those familiar with Terminal in OpenStep for Mach, notes specific to this release are included. For others, there is a section devoted to some of Terminal's less obvious features and some information about Terminal's execution service.
The following new features have been added to Terminal since OPENSTEP for Mach Release 4.2 (NeXT).
/usr/bin/defaults write Terminal LibraryMenu YES
After you restart Terminal, the Shell->Library menu contains an item for each of these files.
eval `tset -s -Q`
You can save a Terminal window or set of such windows to a file, thereby saving your preferred configurations. Everything is saved except the contents of the scrollback buffer; this includes the shell, the location of the window, and whether or not the window is miniaturized. When you choose Save As from the Shell menu, you are given the option of saving all windows or just the main window.
Once you've associated a window with a file, choosing Save flushes the current settings to the file without the intervention of a Save Panel. However, if more than one window belongs with that file, all the associated windows are resaved (the Save menu item indicates this by changing its label to Save Set). This convention allows you to open a set of windows, rearrange them, and type Command-s to save them as a unit to the file.
To have a file opened for you automatically each time you start up Terminal, you can either check a box in the Save Panel brought up by Save As, or you can specify the filename in the Preferences panel under Startup options.
Terminal accepts files dragged into a window and pastes appropriate paths and filenames, plus a space, after the prompt. Dragging an executable file onto Terminal's application icon results in that file being executed in a new Terminal window. If you drop a directory iocn over a Terminal icon, a new shell window is started with that directory as the working directory.
You can drag and drop colors into Terminal windows to enable reverse video and other interesting effects. The color of the selection is settable, as are the color and size of the cursor.
Terminal determines whether shell windows are being used by monitoring the processes inside them. If Terminal thinks something interesting is going on inside a window, it marks the window as "busy" with a mark in the close button. Terminal prompts for confirmation before it closes a busy window and before it quits when there are busy windows.
To make this evaluation, Terminal collects ps-type information about processes it considers relevant and applies a number of heuristics to this information. Usually, Terminal considers shells and a few other garden-variety processes such as su to be innocuous and does not mark windows as busy on their account. But there are exceptions; for example, if the prominent process on the terminal is a shell but it is actively running, the window is considered dirty. You may designate additional "clean" command names (rlogin and telnet are common) in the Preferences panel. If there are running processes on the terminal, the terminal might still be clean if the processes seem to be running happily in the background. But an "interesting" process that's the current process or that you've explicitly suspended with Control-z will always make the window dirty.
Terminal checks the status of windows only when it is likely to have changed. It employs a back-off strategy that prevents the probes from happening too often if a window seems constantly busy.
When Terminal is hidden, the image of text in the application icon "scrolls" to indicate that unviewed output awaits in one or more of the Terminal windows. The title bars of windowshaded Terminal windows are also marked as "dirty" when there is unviewed output.
Two panels, Quick Title and New Command, make it easy to set the title on a window and to start up a new window running a designated command (respectively).
The Quick Title panel displays the current title of the active window for you to edit. However, when you change the title using this panel Terminal won't update any of the information in the future. For example, if a window is titled "/bin/csh 80x24 ~/Term.term" and you edit that window's title to include some text of your own, the new title is treated as a string without embedded variables. It thus won't reflect the size of the window should you change its dimensions. The Preferences panel allows better control over this behavior: You can mix your own text with Terminal's automatically updated information.
The New Command panel uses path searching when it executes (execs) your command. Since the path is the default inherited from Workspace, however, the function's utility is limited. You can add arguments, but shell metacharacters aren't handled correctly.
You can use the program /usr/bin/terminal to open new shell windows in any directory. Without any arguments, the program opens a new shell window in the current directory. (If you have a .login or ..cshrc file that defeats this by changing to the user's home directory, you may have to modify the file.) If you specify a command to run, terminal, by default, runs it without a shell for fastest startup. If you want a shell for the command, you can run the terminal command with the -shell option. For usage information, enter
/usr/bin/terminal -help
For more information on how this utility works, see the Terminal's Execution Service below.
Terminal publishes a Distributed Objects interface so that it can execute commands on the behalf of other applications. See Terminal's Execution Service below for more information.
A process can set the title bar of its terminal window by emitting the following string, without spaces or quotes:
ESC ] 0 ; "Title String" BEL
where ESC is '\033', and BEL is '\007'. The initial 0 can be a 2.
Example
The following csh script code (which can be added to a .cshrc file) shows one example of how you can set the title bar to a "clipped" version of the current directory. It also puts the hostname in the prompt in inverse video:
# begin csh script to set the title bar to the current working directory set homedirectory = ~${user} alias shortpwd 'pwd|sed -e "s|^/private||" -e "s|${homedirectory}|~${user}|"' alias getTitle 'set titleString="`shortpwd|sed -e '\''s|.*[^/]\(/[^/]*/[^/]*/[^/]*/[^/]*\)|...\1|'\'' `"' getTitle if( ${?prompt}) then set hostNm=`hostname` alias cd 'cd \!*; getTitle ; echo -n "]0;${titleString}" ; set prompt = "[7m${hostNm}>[m "' endif cd . #end csh script
Terminal Services are configurable services that allow you to specify UNIX commands that operate on text. (As with other OpenStep Services, these services are available when you're editing text in any application). Terminal services are dynamic and appear in other application's Services menu as soon as you define them. You can edit them by choosing 'Terminal Services...' under Terminal's Apple menu.
When specifying the command associated with a service, you can use the tokens "%s" and "%p" to refer to the location where the selection and prompted input are inserted, repsectively (prompted input is not requested unless "%p" appears in the command).
When you press a key along with the Alternate key, you get the capability for meta key handling. To get this feature, set the following user default:
/usr/bin/defaults write Terminal Meta 0
The meta key generates a character with the eighth bit set. The other options for meta (27 and -1) generate the key preceded by an escape character, or standard NeXTSTEP deadkey handling, respectively. (This feature is probably also available from the preferences panel.)
It is sometimes useful to know the tool that is providing the terminal emulation without changing the TERM environment variable. Terminal now sets 2 environment variables to provide this information to subprocesses:
TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=86 (for example)
The TSTerminalDOServices protocol, declared in the header file NextDeveloper/Headers/Apps/TerminalDOProtocol.h, lets applications request the Terminal application to perform commands on their behalf. A program can use this service if it wants to open up a shell window for the user to interact with, and it may be easier than setting up pipes and doing a fork exec of a program yourself. Note that Terminal cannot provide services if it is not running. Your program might first have to use the Application Kit's NSWorkspace to launch Terminal if the initial connection fails.
A program may run commands in a Terminal window, in which case an Terminal returns an integer window handle enabling the reuse of the window for subsequent commands. In addition, you can specify the window's title, as well as the working directory and environment Terminal should use when it executes the command.
Commands can also be run in the background. In this case, you can pass in an NSData object whose data will be fed to the command's standard input. If you pass in a pointer to an NSData, Terminal can return the output of the command's standard output (and its standard error). If you pass in a pointer to get data back, the data at the pointer should be nil before the command is invoked. When the command completes, the pointer references a newly created NSData containing the output.
For details on the specific methods in the protocol, see the above header file.
The program /usr/bin/terminal, mentioned above in Command for Creating New Terminal Windows, is a simple client that utilizes the TSTerminalDOServices protocol. To get a better idea of how this protocol is implemented, see the source code for this program.
By default, Terminal registers a port for the execution service with the Mach bootstrap server. This means that only processes descended from the Workspace application have access to this service. It is also possible to have Terminal register this port with the Mach netname server, which allows access from other machines on the network. You enable this option by setting the PublicDOServices default:
/usr/bin/defaults write Terminal PublicDOServices YES
Important: Running with this default is a security hazard, as Terminal has no way of verifying who is making the remote connection.
Any user may disable Terminal Services by setting the DisableDOServices default:
/usr/bin/defaults write Terminal DisableDOServices YES
The superuser can disable the service for all users on a given machine using this command:
touch /NextApps/Terminal.app/.DisableDOServices